/*
    SDL_android_main.c, placed in the public domain by Sam Lantinga  3/13/14
*/
#include "../../SDL_internal.h"
#include "../../../../src/audio.h"

#ifdef __ANDROID__

/* Include the SDL main definition header */
#include "SDL_main.h"
/*******************************************************************************
                 Functions called by JNI
*******************************************************************************/
#include <jni.h>
#include <string.h>

/* Called before SDL_main() to initialize JNI bindings in SDL library */
extern void SDL_Android_Init(JNIEnv* env, jclass cls);

/* Start up the SDL app */
void Java_org_libsdl_app_SDLActivity_nativeFinal(JNIEnv* env, jclass cls, jobject obj)
{
	breakPlay=1;
	stopPlay();
}

void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject obj)
{
    /* This interface could expand with ABI negotiation, calbacks, etc. */
    SDL_Android_Init(env, cls);

    SDL_SetMainReady();

    /* Run the application code! */
    int status;
    char *argv[2];
    argv[0] = SDL_strdup("SDL_app");
    //argv[1] = NULL;
    //argv[1] = "mmsh://alive.rbc.cn/am774";
    //argv[1] = "mmsh://alive.rbc.cn/fm974";
    const char* str;
    char str1[128];
       str = (*env)->GetStringUTFChars(env,obj,0);
       if(str != NULL) {
    	   //strcpy(argv[1],str);
    	   strcpy(str1,str);
    	   argv[1] = str1; /* OutOfMemoryError already thrown */
       }else{
    	  argv[1] = "mmsh://alive.rbc.cn/am774";
       }
    status = SDL_main(1, argv);

    //SDL_Delay(40000);
    //stopPlay();
    /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
    /* exit(status); */
}

#endif /* __ANDROID__ */

/* vi: set ts=4 sw=4 expandtab: */
